package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressScan;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressScanMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressScanParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressScanResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressScanService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 扫码分配 服务实现类
 */
@Service
public class ToolExpressScanServiceImpl extends ServiceImpl<ToolExpressScanMapper, ToolExpressScan> implements ToolExpressScanService {

    @Override
    public void add(ToolExpressScanParam param){
        ToolExpressScan entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressScanParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressScanParam param){
        ToolExpressScan oldEntity = getOldEntity(param);
        ToolExpressScan newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressScanResult findBySpec(ToolExpressScanParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<ToolExpressScanResult> findListBySpec(ToolExpressScanParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressScanParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageWellenBySpec(ToolExpressScanParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageWellenBySpec(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressScanParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressScan getOldEntity(ToolExpressScanParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressScan getEntity(ToolExpressScanParam param) {
        ToolExpressScan entity = new ToolExpressScan();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public boolean saveBatchList(List<ToolExpressScanParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public void deleteBySpec(ToolExpressScanParam scanParam) {
		this.baseMapper.deleteBySpec(scanParam);
		
	}

	@Override
	public void updateBySpec(ToolExpressScanParam toolExpressScanParam) {
		this.baseMapper.updateBySpec(toolExpressScanParam);
	}

	@Override
	public void updateArrangeBySpec(ToolExpressScanParam scanUpdate) {
		this.baseMapper.updateArrangeBySpec(scanUpdate);
		
	}

}
